package com.springboot.blog.service.impl;

import com.springboot.blog.beans.Blog;
import com.springboot.blog.beans.BlogComment;
import com.springboot.blog.beans.PageBlog;
import com.springboot.blog.dao.CommentDao;
import com.springboot.blog.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Resource
    private CommentDao commentDao;

    @Override
    public PageBlog<BlogComment> page(Integer pageNo, Integer pageSize) {
        PageBlog<BlogComment> page = new PageBlog<>();
        //设置当前页面
        page.setPageNo(pageNo);

        //求当前页的开始索引
        int begin = (page.getPageNo()-1) * pageSize;
        //求当前页数据
        List<BlogComment> items = commentDao.queryCommentForItems(begin,pageSize);
        //设置当前页数据
        page.setItems(items);
        return page;
    }
}
